package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.SpecialityMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.RoleExample;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.Speciality;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.SpecialityExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecialityServiceImpl implements ISpecialityService{
    @Autowired
    private SpecialityMapper specialityMapper;
    @Override
    public int insertSpeciality(Speciality speciality) {
        return specialityMapper.insert(speciality);
    }

    @Override
    public List<Speciality> queryAllSpeciality() {
        return specialityMapper.selectAll();
    }

    @Override
    public Speciality querySpecialityById(Integer id) {
        return specialityMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteSpecialityById(Integer id) {
        return specialityMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateSpecialityById(Speciality speciality) {
        return specialityMapper.updateByPrimaryKey(speciality);
    }

    @Override
    public int queryTotalSpecialityCount() {
        SpecialityExample specialityExample = new SpecialityExample();
        SpecialityExample.Criteria criteria = specialityExample.createCriteria();
        criteria.getAllCriteria();
        return (int) specialityMapper.countByExample(specialityExample);
    }

    @Override
    public List<Speciality> querySpecialityByPage(int pageNow,int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<Speciality> roles = this.queryAllSpeciality();
        PageInfo<Speciality> specialityPageInfo = new PageInfo<>(roles);
        return specialityPageInfo.getList();
    }
}
